<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>授权</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<style type="text/css">
			html,body{
				font-size: 16px;
			}
			#auth-status{
				font-size: .3rem;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 1.3rem 0;
			}
			.box{
				height: 1rem;
				width: 1rem;
				padding: 0 .26rem;
			}
			.box>img{
				height: 1rem;
				width: 1rem;
			}
			.result-box{
				width: 2rem;
				text-align: center;
			}
			.pointer{
				display: inline-block;
				height: 0.12rem;
				width: 0.12rem;
				border-radius: 50% 50%;
				background-color: rgba(216,216,216,0.90);
			}
			.pointer-box{
				padding: 0.1rem 0;
			}
			.finish{
				width: 90%;
				margin: 2rem auto 0;
				height: 0.98rem;
				font-size: .3rem;
				background-color: #4a90e2;
				color: #FFFFFF;
				line-height: 0.98rem;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<div id="auth-status">
			<div class="box">
				<img src="./img/alipay.png" alt="alipay" />
			</div>
			<div class="result-box">
				<div id="auth-result">授权中...</div>
				<div class="pointer-box">
					<div class="pointer"></div>
					<div class="pointer"></div>
					<div class="pointer"></div>
					<div class="pointer"></div>
					<div class="pointer"></div>
					<div class="pointer"></div>
				</div>
			</div>
			<div  class="box">
				<img src="./img/icon.png" alt="logo"/>
			</div>
		</div>
		
		<div class="finish">完 成</div>
		<script src="./js/base.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			// 支付宝授权页
			handleAuth();

			function handleAuth(){	
				var url = window.baseUrl + "paymentchannel/alipay/auth_callback";
				var shop_id = GetQueryString('shop_id');
				var app_id = GetQueryString('app_id');
				var app_auth_code = GetQueryString('app_auth_code');
				var data = "shop_id="+shop_id+"&app_id="+app_id+"&app_auth_code="+app_auth_code;
				// url, data, fn
				
			    var xhr ;
			    if(window.XMLHttpRequest){
			    	xhr = new XMLHttpRequest();
			    }else{
			    	xhr = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			    xhr.open("POST", url, true);
			    // 添加http头，发送信息至服务器时内容编码类型
			    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
			    xhr.onreadystatechange = function() {
			      if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
//			        alert(xhr.responseText);
			        if(JSON.parse(xhr.responseText).resp_code === "000000"){
			        	document.getElementById("auth-result").innerHTML = "授权成功！";
			        }else{
			        	document.getElementById("auth-result").innerHTML = "授权失败！";
			        }
			        
			      }
			    };
			    xhr.send(data);
			}
			
			
			function GetQueryString(name){
			    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			    var r = window.location.search.substr(1).match(reg);
			    if(r!=null)return  unescape(r[2]);
			    return null;
			}
		</script>
		<script type="text/javascript">
			// 自适应字体大小
			(function () {
				var designW = 750;  //设计稿宽
				var font_rate = 100;
				//适配
				document.getElementsByTagName("html")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
				document.getElementsByTagName("body")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
		
				//监测窗口大小变化
				window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function () {
					document.getElementsByTagName("html")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
					document.getElementsByTagName("body")[0].style.fontSize = document.body.offsetWidth / designW * font_rate + "px";
				}, false);
			})();		
		</script>
	</body>
</html>
